using UnityEngine;

namespace Voodoo.Meta.RVModules
{
	public class KeyCollectable : MonoBehaviour
	{
		private const string _collectTrigger = "Collect";

		private const string _idleAnimation = "KeyIdle";

		public Collider keyCollider;

		public GameObject particleGetKey;

		public GameObject particleGlow;

		public GameObject particleEffect;

		public AudioClip collectSound;

		private bool _collected;

		private void Start()
		{
			particleGlow.SetActive(value: true);
		}

		public void DoCollect()
		{
			if (!_collected)
			{
				ChestRoomAdapter.DoVibrateMedium();
				particleGlow.SetActive(value: false);
				particleGetKey.gameObject.SetActive(value: true);
				keyCollider.enabled = false;
				ChestRoomKeysManager.Instance.ComputeKeyCollected(ChestRoomAdapter.GetCurrentLevel());
				ChestRoomAdapter.PlaySound(collectSound);
				_collected = true;
				Object.Instantiate(particleEffect).transform.position = base.transform.position;
				Object.Destroy(base.gameObject);
				Debug.LogError("Collected key");
			}
		}

		private void OnTriggerEnter(Collider other)
		{
			if (!_collected && other.GetComponent<Head>() != null)
			{
				DoCollect();
			}
		}

		public void OnDisable()
		{
			particleGetKey.gameObject.SetActive(value: false);
		}
	}
}
